package edu.nakan.sortvietnamesename;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    Scanner input = new Scanner (System.in);
        String[] Sv = new String[100];
        String[] Ten = new String[100];

        //input
        System.out.println("Number of Students : " );
        int n = input.nextInt();
        
        for (int i = 0; i < n; i ++) {
            input = new Scanner(System.in);
            System.out.print("* Student "+ (i+1) + " : ");
            Sv[i] = new String();
            Sv[i] = input.nextLine();
        }

        //get name from full name
        for (int i = 0; i < n; i ++)
        {
            String[] names = Sv[i].split(" ");
            Ten[i] = new String(names[names.length - 1]);
        }

        //sorting
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if (Ten[i].compareTo(Ten[j]) > 0) {
                    String tmp = new String();
                    tmp = Sv[i];
                    Sv[i] = Sv[j];
                    Sv[j] = tmp;
                }
            }
        }
        //print all
        for (int i = 0 ; i < n; i ++) {
            System.out.println(Sv[i]);
        }

    }
}
